package com.zengqingfa.springboot.validation.demo.entity;

import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @fileName: UserDto
 * @author: zengqf3
 * @date: 2020-10-6 17:01
 * @description:
 */
@Data
public class UserDto {

    @Min(value = 10000L, groups = Update.class)
    @NotNull(message = "userId不能为空", groups = Update.class)
    private Long userId;

    @NotEmpty(message = "用户名称不能为空", groups = {Save.class})
    @Length(min = 2, max = 10, groups = {Save.class, Update.class})
    private String userName;

    @NotNull(groups = {Save.class, Update.class})
    @Valid
    private Job job;

    @Data
    public static class Job {

        @Min(value = 1, groups = Update.class)
        @NotNull(message = "jobId不能为空", groups = Update.class)
        private Long jobId;

        @NotNull(message = "jobName不能为空", groups = {Save.class, Update.class})
        @Length(min = 2, max = 10, groups = {Save.class, Update.class})
        private String jobName;
    }

    /**
     * 保存的时候校验分组
     */
    public interface Save {
    }

    /**
     * 更新的时候校验分组
     */
    public interface Update {
    }


}
